/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
function showPopupSmall(title, content) {
    var htmltex = '  <div id="small_popup"class="zmpopup pu_small">';
    htmltex += '            <a href="#" class="zmpuclose" title="Đóng"><span></span></a>';
    htmltex += '            <div class="zmputitle">';
    htmltex += '	<strong>' + title + '</strong>';
    htmltex += '</div>';
    htmltex += '<div class="zmpucont">';
    htmltex += content;
    htmltex += '</div>';
    htmltex += '<div class="zmpubot">';
    htmltex += '<div class="zmpubtn">';
    htmltex += '<a href="#" class="submitbtn">OK</a>';
    htmltex += '</div>';
    htmltex += '</div>';
    htmltex += '</div>';
    zm('body').append(htmltex);

    var h = zm("#small_popup").height();
    var w = zm("#small_popup").width();
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) === 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var scro= window.scrollY;
    var left = (myWidth/ 2) - (w / 2);
    var top = (myHeight / 2) - (h / 2)+scro;
    zm("#small_popup").css("top", top + "px");
    zm("#small_popup").css("left", left + "px");
    zm('.zmpuclose').click(function() {
        zm("#small_popup").remove();
    });
    zm('.submitbtn').click(function() {
        zm("#small_popup").remove();
    });
    var elememt = zm('#small_popup');
    dragPopup(elememt);

}
function showPopupMedium(ussername, value, idsurvey, iduser) {
    var htmltex = '<div id="mudium_popup" class="zmpopup pu_med">';
    htmltex += '<a href="#" class="zmpuclose" title="Đóng"><span></span></a>';
    htmltex += '<div class="zmputitle">';
    htmltex += '<strong>' + value.title + '(' + ussername + ')' + '</strong>';
    htmltex += '</div>';
    htmltex += '<div class="zmpucont"  >';
    for (var i = 0; i < value.answers.length; i++)
    {
        var answer = value.answers[i];
        var index = i + 1;
        htmltex += '<div class="pop-ques">';
        htmltex += '<div class="pop-ques-title">';
        htmltex += '<span class="question-span">Câu hỏi ' + index + ':</span>';
        htmltex += ' <span>' + answer.title + '</span>';
        if (answer.requrie === true) {
            htmltex += ' <span class="require">(*)</span>';
        }
        htmltex += '</div>';
        htmltex += '<div class="pop-ques-content">';
        if (answer.type === singleline || answer.type === multiline) {
            htmltex += answer.answer;

        } else {
            for (var j = 0; j < answer.choice.length; j++) {
                if (answer.answer[j] === "0") {
                    htmltex += ' <input type="checkbox" disabled><span>' + answer.choice[j] + '</span><br>';
                } else {
                    htmltex += ' <input type="checkbox" disabled checked><span>' + answer.choice[j] + '</span><br>';
                }
            }

        }
        htmltex += '</div>';
        htmltex += ' </div>';
    }

    htmltex += '</div>';
    htmltex += ' <div class="zmpubot">';
    htmltex += '<div class="zmpubtn">';
    htmltex += '<a href="#" id="removeresponse" class="submitbtn">Xóa</a><a href="#" class="cancelbtn">Đóng</a>';
    htmltex += ' </div>';
    htmltex += '  </div>';
    htmltex += '  </div>';
    zm('body').append(htmltex);

    var x = event.pageX;
    var y = event.pageY;
    var h = zm("#mudium_popup").height();
    var w = zm("#mudium_popup").width();
    var top = y + 15;
    if ((y + w) > window.innerHeight) {
        top = (window.innerHeight / 2) - (h / 2);
    }
    zm("#mudium_popup").css("top", top + "px");
    zm("#mudium_popup").css("left", x + 30 + "px");
    zm('.zmpuclose').click(function() {
        zm("#mudium_popup").remove();
    });
    zm('.cancelbtn').click(function() {
        zm("#mudium_popup").remove();
    });
    zm('#removeresponse').click(function() {
        var arrIDuser = new Array();
        arrIDuser[0] = iduser;
        ajaxDelResponse(idsurvey, arrIDuser);
        zm("#mudium_popup").remove();
    });
    var elememt = zm('#mudium_popup');
    dragPopup(elememt);
}
function dragPopup(elememt) {
    var flag = false;
    var x = event.pageX;
    var y = event.pageY;
    elememt.mousedown(function() {
        x = event.pageX;
        y = event.pageY;

        flag = true;

    });
    elememt.mouseup(function() {
        flag = false;
    });
    elememt.mousemove(function() {
        if (flag === true) {

            var x_new = event.clientX;
            var y_new = event.clientY;
            var postion = elememt.position();
            elememt.css("left", postion.left + (x_new - x) + "px");
            elememt.css("top", postion.top + (y_new - y) + "px");
            x = event.pageX;
            y = event.pageY;

        }

    });

}

function setElement(className,html){
    zm('.wrap-page').append(html);
    className = '.' + className;
    var element = zm(className);
    var h = element.height();
    var w = element.width();
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h);
    element.css("background-color","#FFFFFF");
    element.css("position",  "fixed");
    element.css("left",  left+"px");    
    element.css("top",  top+"px");
}